function HandleReceiveMail(gui, user, date, options, data) {
  this._gui = gui;
  this._user = user;
  this._date = date;
  this._options = options;
  this._data = data;
  
  this._popupBox = new ModulePopupBoxSimple();
  this._popupBox2 = new ModulePopupBox();
  this._models = this._data['pz_model'];
  this._states = this._data['pz_model_state'];
  this._transitions = this._data['pz_model_transition'];
  this._task = this._data['0'][0];
  
  this._createElements();
};

HandleReceiveMail.prototype._createElements = function() {
  var _self = this;
  DOMUtils.removeChildElements(this._gui.branch);
  DOMUtils.removeChildElements(this._gui.receiver);
  DOMUtils.removeChildElements(this._gui.company);
  DOMUtils.removeTableRows(this._gui.purchasetable, 1);
  
  this._gui.sentdate.appendChild(document.createTextNode(SimpleDate.format(SimpleDate.fromStamp(this._task.sent_date))));
  this._gui.receiveddate.appendChild(document.createTextNode((this._task.received_date != 0) ? SimpleDate.format(SimpleDate.fromStamp(this._task.received_date)) : ''));
  
  this._gui.receiver.appendChild(document.createTextNode(this._task.receiver));
  this._gui.branch.appendChild(document.createTextNode(this._task.branch));
  this._gui.company.appendChild(document.createTextNode(this._task.company));
  this._gui.code.appendChild(document.createTextNode(this._task.code));
  this._gui.packagenumber.appendChild(document.createTextNode(this._task.package_number));
  this._gui.comment.value = this._task.comment;
  
  if (this._task.tasks.length == 0) {
    var tr = this._gui.purchasetable.insertRow(-1);
    var td = tr.insertCell(-1);
    td.colSpan = 3;
    td.style.height = '24px';
    td.style.textAlign = 'left';
    td.style.paddingLeft = '5px';
    td.appendChild(document.createTextNode('n/a'));
  }

  for (var i = 0, il = this._task.tasks.length; i < il; i++) {
    var task = this._task.tasks[i];
    var tr = this._gui.purchasetable.insertRow(-1);
    var td = tr.insertCell(-1);
    td.style.height = '24px';
    td.style.textAlign = 'left';
    td.style.paddingLeft = '5px';
    td.appendChild(document.createTextNode(task.branch + task.customer_id));
    
    td = tr.insertCell(-1);
    td.style.height = '24px';
    td.style.textAlign = 'left';
    td.style.paddingLeft = '5px';
    var span = document.createElement('span');
    span.style.fontWeight = 'bold';
    span.appendChild(document.createTextNode(task.pi_quantity + 'X'));
    td.appendChild(span);
    td.appendChild(document.createTextNode(PPublishUtils.customerName(task.bride_name, task.groom_name)));
    
    td = tr.insertCell(-1);
    td.style.height = '24px';
    td.style.textAlign = 'left';
    td.style.paddingLeft = '5px';
    td.appendChild(document.createTextNode(this._states[0].name));
  }
  
  this._gui.receive.onclick = function() { var pos = DOMUtils.findPos(this);
                                           var tasks = []; events = []; tracks = [];
                                           var states = MiscUtils.find(_self._states, [{ attrs: ['id'], value: _self._task.state_id }]);
                                           var transitions = MiscUtils.find(_self._transitions, [{ attrs: ['source_id'], value: _self._task.state_id }]);
                                           var e = ModelUtils.evt(_self._task, states[0], transitions[0], _self._user, _self._date);
                                           var t = ModelUtils.trk(_self._task, transitions[0]);
                                           events.push(e);
                                           tracks.push(t);
                                           _self._task.state_id = transitions[0].target_id;
                                           _self._task.deadline = parseInt(_self._date, 10) + 86400 * transitions[0].day;
                                           _self._task.is_completed = 1;
                                           _self._task.received_date = _self._date;
                                           _self._task.receiver = _self._user.name;
                                           tasks.push(_self._task);
                                          for (var j = 0, jl = _self._task.tasks.length; j < jl; j++) {
                                            var tk = _self._task.tasks[j];
                                            var states1 = MiscUtils.find(_self._states, [{ attrs: ['id'], value: tk.state_id }]);
                                            var transitions1 = MiscUtils.find(_self._transitions, [{ attrs: ['source_id'], value: tk.state_id }]);
                                            var e1 = ModelUtils.evt(tk, states1[0], transitions1[0], _self._user, _self._date);
                                            var t1 = ModelUtils.trk(tk, transitions1[0]);
                                            events.push(e1);
                                            tracks.push(t1);
                                            tk.state_id = transitions1[0].target_id;
                                            tk.deadline = parseInt(_self._date, 10) + 86400 * transitions1[0].day;
                                            tk.received_date = _self._date;
                                            tk.is_signed = 1;
                                            tasks[tasks.length] = tk;
                                          }
                                          var func = function() { var div = document.createElement('div');
                                                                  div.appendChild(document.createTextNode('Receive Successfully!'));
                                                                  var func1 = function() { _self._popupBox._close();
                                                                                           history.back();
                                                                                         };
                                                                  MiscUtils.dialog(_self._popupBox, pos, div, func1, null, null);
                                                                }
                                          new RequestUtils()._write2([{ n: 'pz_task', a: tasks, r: [] }, { n: 'pz_task_event', a: events, r: [] }, { n: 'pz_task_track', a: tracks, r: [] }], func, { pos: pos });
                                         };
  this._gui.back.onclick = function() { history.back(); };
};